#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	for (int i = 0; i < m; i++) cin >> a[i];
	sort(a.begin(), a.end());
	for (int l = 0, r = m - 1; l <= r && n >= 1; l++, r--)
	{
		if (l == r)
		{
			n--;
			cout << a[l] << ' ' << a[l] << ' ' << a[l] << ' ' << a[l] << ' ' << a[l] << ' ' << a[l] << '\n';
		}
		else
		{
			int cnt = 1;
			for (int j = 0; j < 6; j++)
			{
				if (cnt == 1) cout << a[l] << ' ';
				else cout << a[r] << ' ';
				cnt ^= 1;
			}
			cout << '\n';
			if (--n == 0) return;
			cnt = 0;
			for (int j = 0; j < 6; j++)
			{
				if (cnt == 1) cout << a[l] << ' ';
				else cout << a[r] << ' ';
				cnt ^= 1;
			}
			n--;
			cout << '\n';
		}
	}
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}